(browse-url-interactive-arg): Enable user to explicitly select the text to
authorJuanma Barranquero <lekktu@gmail.com>
Sun, 23 May 2004 22:35:59 +0000 (22:35 +0000)
committerJuanma Barranquero <lekktu@gmail.com>
Sun, 23 May 2004 22:35:59 +0000 (22:35 +0000)
be taken as URL.

lisp/net/browse-url.el

index 8000e49c6d8d983eef77c99b8cad170f14399edf..e98b3d815ab3228bffff29ca40874839c02344d9 100644 (file)
@@ -577,13 +577,21 @@ down (this *won't* always work)."
 
 (defun browse-url-interactive-arg (prompt)
   "Read a URL from the minibuffer, prompting with PROMPT.
-Default to the URL at or before point.  If invoked with a mouse button,
-set point to the position clicked first.  Return a list for use in
-`interactive' containing the URL and `browse-url-new-window-flag' or its
+If `transient-mark-mode' is non-nil and the mark is active,
+defaults to the current region, else to the URL at or before
+point.  If invoked with a mouse button, set point to the
+position clicked first.  Return a list for use in `interactive'
+containing the URL and `browse-url-new-window-flag' or its
 negation if a prefix argument was given."
   (let ((event (elt (this-command-keys) 0)))
     (and (listp event) (mouse-set-point event)))
-  (list (read-string prompt (browse-url-url-at-point))
+  (list (read-string prompt (or (and transient-mark-mode mark-active
+                                    ;; rfc2396 Appendix E.
+                                    (replace-regexp-in-string
+                                     "[\t\r\f\n ]+" ""
+                                     (buffer-substring-no-properties
+                                      (region-beginning) (region-end))))
+                               (browse-url-url-at-point)))
        (not (eq (null browse-url-new-window-flag)
                 (null current-prefix-arg)))))